package com.molichuxing.services.infrastructure.service.impl;


import com.molichuxing.services.infrastructure.bean.YearlyInspectionLogBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.YearlyInspectionLogMapper;
import com.molichuxing.services.infrastructure.dto.request.create.YearlyInspectionCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.YearlyInspectionLogCreateDto;
import com.molichuxing.services.infrastructure.dto.response.YearlyInspectionLogCountDto;
import com.molichuxing.services.infrastructure.dto.response.YearlyInspectionLogDto;
import com.molichuxing.services.infrastructure.service.YearlyInspectionLogService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 车牌 服务实现类
 * </p>
 *
 * @author
 * @since 2020-05-11
 */
@Service("yearlyInspectionLogService")
public class YearlyInspectionLogServiceImpl implements YearlyInspectionLogService {

    private static final Logger log = Logger.getLogger(YearlyInspectionLogServiceImpl.class);

    @Resource
    private YearlyInspectionLogMapper yearlyInspectionLogMapper;


    @Override
    public Integer createYearlyInspectionLog(YearlyInspectionLogCreateDto createDto) {
        YearlyInspectionLogBean yearlyInspectionLogBean = Convert.toYearlyInspectionLogBean(createDto);
        yearlyInspectionLogMapper.create(yearlyInspectionLogBean);
        return yearlyInspectionLogBean.getId();
    }

    @Override
    public List<YearlyInspectionLogDto> getYearlyInspectionLogListByCarId(Integer carId) {
        List<YearlyInspectionLogBean> yearlyInspectionLogList = yearlyInspectionLogMapper.getYearlyInspectionsLogListByCarId(carId);
        return Convert.toYearlyInspectionLogDto(yearlyInspectionLogList);
    }

    @Override
    public Boolean createYearlyInspectionLogBatch(List<YearlyInspectionLogCreateDto> createDtoList) {
        List<YearlyInspectionLogBean> yearlyInspectionLogList = Convert.toYearlyInspectionLogBeanList(createDtoList);
        int result = yearlyInspectionLogMapper.createBatch(yearlyInspectionLogList);
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Map<Integer, Integer> getYearlyInspectionLogCount(List<Integer> carIdList) {
        List<YearlyInspectionLogCountDto> yearlyInspectionLogCount = yearlyInspectionLogMapper.getYearlyInspectionLogCount(carIdList);
        if (null == yearlyInspectionLogCount || yearlyInspectionLogCount.size() < 1) {
            return null;
        }

        Map<Integer, Integer> returnMap=new HashMap<>();
        for(YearlyInspectionLogCountDto yearlyInspectionLogCountDto:yearlyInspectionLogCount){
            Integer carId = yearlyInspectionLogCountDto.getCarId();
            Integer count = yearlyInspectionLogCountDto.getCount();
            returnMap.put(carId,count);
        }

        return returnMap;
    }

    @Override
    public YearlyInspectionLogDto getNewYearlyInspectionLogByCarId(Integer carId) {
        YearlyInspectionLogBean yearlyInspectionLogBean = yearlyInspectionLogMapper.getNewYearlyInspectionLogByCarId(carId);
        return Convert.toYearlyInspectionLogDto(yearlyInspectionLogBean);
    }


}
